package com.allinpay.merchantweb.common.utils;

public class StringUtil {

	/**
	 * 判断字符串是否为空.
	 * 
	 * @param src
	 * @return
	 */
	public static boolean isEmpty(final String src) {
		if (null == src || "".equals(src)) {
			return true;
		}
		return false;
	}

	/**
	 * 把key=value追加到加密/签名字符串最后.
	 * 
	 * @param buf
	 * @param key
	 * @param value
	 */
	public static void appendSignPara(StringBuffer buf, String key, String value) {
		if (!StringUtil.isEmpty(value)) {
			buf.append(key).append('=').append(value).append('&');
		}
	}
	
	
	/**
	 * 手机号掩码 1387****678
	 * @param phoneNum
	 * @return
	 */
	public static String markPhoneNum(String phoneNum){
		if(StringUtil.isEmpty(phoneNum)){
			return "";
		}
		String trimPhoneNum = phoneNum.trim();
		if(trimPhoneNum.length()>=11){
			return trimPhoneNum.substring(0, 4)+"****"+trimPhoneNum.substring(8);
		}else{
			return trimPhoneNum;
		}
	}
	
	/**
	 * 手机号掩码 138****6783
	 * @param phoneNum
	 * @return
	 */
	public static String markPhoneNum2(String phoneNum){
		if(StringUtil.isEmpty(phoneNum)){
			return "";
		}
		String trimPhoneNum = phoneNum.trim();
		if(trimPhoneNum.length()>=11){
			return trimPhoneNum.substring(0, 3)+"****"+trimPhoneNum.substring(7);
		}else{
			return trimPhoneNum;
		}
	}
}
